package com.sc.core.util;

import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class Sc {
    private final ApplicationContext applicationContext;
    private static Sc sc;

    Sc(ApplicationContext applicationContext){
        this.applicationContext = applicationContext;
        sc = this;
    }

    public static <T> T getBean(Class<T> clazz) {
        return sc.applicationContext.getBean(clazz);
    }

    public static Object getInnerStaticClass(Class<?> outerClass, String innerClassName) {
        try {
            return outerClass.getDeclaredField(innerClassName).get(null);
        } catch (IllegalAccessException | NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
    }
}
